﻿using LX.Core.Validation;
using S4Store.Domain;
using S4Store.Persistent;
using System.Linq;

namespace S4Store.Service.Valid.StoreValid
{
    public class Modify : ValidExpression<Store>
    {
        public S4StoreDataContext PersistentContext { get; set; }

        public override void ValidEntity(ValidationResult result, Store entity)
        {
            NoEmpty(result, "名称", entity.Name);
            if(PersistentContext.Set<Store>().AsQueryable().FirstOrDefault(t=>t.Name==entity.Name&&t.Id!=entity.Id)!=null)
            {
                PushError(result, "已存在相同名称的店");
            }
        }
    }
}
